<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "books".
 *
 * @property string $uid
 * @property string $table_id
 * @property string $name
 * @property string $category
 * @property string $socure
 * @property string $state
 * @property integer $update_time
 * @property integer $create_time
 */
class Books extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'books';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid'], 'required'],
            [['update_time', 'create_time'], 'integer'],
            [['uid', 'table_id', 'name', 'category', 'socure'], 'string', 'max' => 36],
            [['state'], 'string', 'max' => 10],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'uid' => 'Uid',
            'table_id' => 'Table ID',
            'name' => 'Name',
            'category' => 'Category',
            'socure' => 'Socure',
            'state' => 'State',
            'update_time' => 'Update Time',
            'create_time' => 'Create Time',
        ];
    }

    /**
     * 动态建表
     * @author  LiShaoWei
     * @access  public
     * @since   1.0
     */
    public function safeUp($title)
    {
        $book='book_'.$title;
        $html="DROP TABLE IF EXISTS $book;
                CREATE TABLE $book (
                  `id` int(11) NOT NULL AUTO_INCREMENT,
                  `title` char(30) NOT NULL,
                  `content` TEXT DEFAULT NULL,
                  `socure` char(200) DEFAULT NULL,
                  `create_time` INT,
                  PRIMARY KEY (`id`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8";
        return Yii::$app->db->createCommand($html)->execute();
    }
}
